package cqu.java.timer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Run1 {
	//private static Timer timer = new Timer();
	//把Timer定义为守护进程
	private static Timer timer = new Timer(true);
	
	static public class MyTask extends TimerTask{
		@Override
		public void run() {
			System.out.println("运行了！时间为："+new Date());
		}
	}
	
	public static void main(String[] args) {
		
		try {
			MyTask myTask = new MyTask();
			SimpleDateFormat simpleDateFormat  = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String dataString = "2016-07-06 16:50:40";
			Date date = simpleDateFormat.parse(dataString);
			
			System.out.println("String time = "+date.toLocaleString()+"   Current time = "+new Date().toLocaleString());
			
			timer.schedule(myTask, date);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	
}
